#ifndef BUS_H
#define BUS_H
#include <string>
#include <iostream>
#include <utility>
#include "TimeTable.h"
#include "Period.h"
#include <stdlib.h>
using std::string;
class RunningTable;
enum STATE {
    run, waiting
};
class Bus
{
public:
	Bus() = default;
	Bus(string l, string m, string d, int c, Date date, Period p, int r, int rt)
		: license(std::move(l)), model(std::move(m)), driver(std::move(d)), carrying(c), period(p), running(r), restTime(rt)
	{
	    times = (p.getEndTime() - p.getStartTime()) / (r + rt);
	    timeTable = TimeTable(p.getStartTime(), p.getEndTime(), date, rt, running);
        protoRunningTable = RunningTable(p.getStartTime(), p.getEndTime(), date, rt, running);
	}
	inline Time startTime() const { return period.getStartTime();}
	inline Time endTime() const { return period.getEndTime();}
	inline TimeTable& getTimeTable() {return timeTable;}
    inline RunningTable* getRunningTable() {return runningTableNow;}
    inline TimeTableItem& getCurrentRunningTableItem() {return runningTableNow->getItem(numberOfItem);}
    inline STATE getCurrentState() const {return state;}
    inline bool isRunning() const {return state == run;}
    inline int getNumOfItem() const {return numberOfItem;}

	void startADay();
	bool isFull();
	void addPerson();
    void endADay();
    bool tryEnd(const Time& now);
    bool ifRun(const Time& now);
    bool tryRun(const Time& now);
    bool tryStop(const Time& now);
private: 
    //Basic info
	string license;
	string model;
	string driver;
	int carrying;
	int running;
	int restTime;
	int times;
	Period period;
	TimeTable timeTable;
	RunningTable protoRunningTable;
	RunningTable* runningTableNow;
    //State
	STATE state = waiting;
	int numberOfItem = 0;
};

#endif
